<?php

namespace app\api\controller\xykeep;
use app\common\controller\Api;

use app\api\model\xykeep\Course as CourseModel;
use app\api\model\xykeep\Category as CategoryModel;

/**
 * XYkeep课程接口
 */
class Course extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 课程列表-分页
     */
    public function list()
    {
        $params = $this->request->post();

        $where = [];

        if(isset($params['category_id']) && $params['category_id']!==''){
            $where['category_id'] = $params['category_id'];
        }

        $data = CourseModel::where($where)->paginate();
        $this->success('课程列表', $data);
    }

    /**
     * 课程详情
     */
    public function detail()
    {
        $id = $this->request->get('id');
        $detail = CourseModel::getDetail($id);

        if(!$detail){
            $this->error('课程不存在！');
        }
        // 记录足记
//        UserViewModel::addView($detail,'course');
        $this->success('课程详情', $detail);
    }


    /**
     * 课程分类
     */
    public function category()
    {
        $services = CategoryModel::where([
            'type' => 'course'
        ])->select();
        $this->success('课程分类',$services);
    }

	
	
}